package com.yuanfeng.action.admin.type.dao;
import com.yuanfeng.pojo.Types;
import java.util.List;
import java.util.UUID;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class TypeDaoImpl extends HibernateDaoSupport implements TypeDao {
	/**
	 * 删除分类
	 * @param types
	 */
	@Override
	public void delete(Types types) {
		List<Types> list =  (List<Types>)this.getHibernateTemplate().find("from Types where id=?", types.getId());
		this.getHibernateTemplate().delete(list.get(0));
		this.getHibernateTemplate().flush();
	}

	/**
	 * 查询分类
	 * @return
	 */
	public List<Types> queryTypes(){

		List<Types> types = (List<Types>)this.getHibernateTemplate().find("from Types");
		return types;
	}
	/**
	 * 添加分类
	 */
	public Types add(Types types){

		Types types1 = new Types();
		types1.setId(UUID.randomUUID().toString().replace("-", ""));
		types1.setName(types.getName());
		types1.setDescr(types.getDescr());
		this.getHibernateTemplate().save(types1);
		this.getHibernateTemplate().flush();
		return types1;
	}
}
